using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Boomer.Source.FrameWork.State_and_Screen_Manager.Screen_Manager;
using FrameWork.Source.CMenu_class;
using FrameWork.Source.Texture;
using FrameWork.Source.Resource_Manager;
using Microsoft.Xna.Framework;
using FrameWork.Source.Screen;
using Microsoft.Xna.Framework.Input;
using FrameWork.Source.Global_variables;

namespace Boomer.Source.FrameWork.State_and_Screen_Manager.State.MenuState.MenuScreen
{
    class MainMenuScreen : IScreen
    {

        private CMenu m_pMainMenu;
        private CTexture m_pMenuBG;

        public MainMenuScreen(int index, string screenName, bool isActive , ScreenManager manager)
            : base(index, screenName, isActive,manager)
        {
            m_pMainMenu = null;
            m_pMenuBG = null;
        }

        public override void init()
        {
            m_pMenuBG = CResourceManager.getInstance().getImage((int)CResourceManager.IMG_MENU.MAINBG);

            CMenuItem pNewGame = new CMenuItem();
            pNewGame.createItem( "New game" , null , 330 ,60 , new Vector2( 221, 282 ) , true );

            CMenuItem pOption = new CMenuItem();
            pOption.createItem("Option", null, 330, 60, new Vector2(221, 350), true);

            CMenuItem pAbout = new CMenuItem();
            pAbout.createItem("About", null, 330, 60, new Vector2(221, 418), true);

            CMenuItem pExit = new CMenuItem();
            pExit.createItem("Exit", null, 330, 60, new Vector2(221, 491), true); 

            m_pMainMenu = new CMenu();

            m_pMainMenu.addItem(pNewGame);
            m_pMainMenu.addItem(pOption);
            m_pMainMenu.addItem(pAbout);
            m_pMainMenu.addItem(pExit);
            base.init();
        }

        public override void update(float deltaTime)
        {
            
            base.update(deltaTime);
        }

        public override void render()
        {
            

            m_pMenuBG.drawImage(new Vector2(0, 0), Color.White);

            base.render();
        }

        public override void processInput(float deltaTime)
        {
            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed && CGLOBAL.g_isReleaseKey)
            {
                CGLOBAL.g_isReleaseKey = false;
                CMenuItem pItem = null;
                m_pMainMenu.picking(mouse.X, mouse.Y, ref pItem);
                if (pItem != null)
                {
                    if (pItem.m_strName == "New game")
                    {
                        this.m_pScreenManager.m_pStateManager.setNextState(new MainGameState(m_pScreenManager.m_pStateManager));
                    }
                    if (pItem.m_strName == "Option")
                    {
                        this.m_pScreenManager.setScreen("option screen", false, true);
                    }
                    if (pItem.m_strName == "About")
                    {
                        this.m_pScreenManager.setScreen("about screen", false, true);
                    }
                    if (pItem.m_strName == "Exit")
                    {
                        this.m_pScreenManager.m_pStateManager.m_pGame.Exit();
                    }
                }
            }

            if (mouse.LeftButton == ButtonState.Released)
            {
                CGLOBAL.g_isReleaseKey = true;
            }
            
            base.processInput(deltaTime);
        }
    }
}
